package com.huazai.Util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
    private static final String URL = "jdbc:mysql://localhost:3306/information";
    private static final String user = "root";
    private static final String password = "8023u8023U";
    public static String JDBCname = "com.mysql.cj.jdbc.Driver";

    public static Connection ConnectDB() {
        Connection conn = null;
        try {
            Class.forName(JDBCname);
            System.out.println("Driver loading succeed !");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("Driver loading failed !");
        }
        try {
            conn = DriverManager.getConnection(URL,user,password);
            System.out.println("Connect to database succeed !");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            System.out.println("Connect to database failed !");
        }
        return conn;
    }
}